import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'
import type { DataExportAO } from '/@/model/cn/core/tool/ao/DataExportAO'

import dataSourceService from '/@/api/cn/core/kpis/dataSourceService'

import type { DataSource } from '/@/model/cn/core/kpis/eo/DataSource'
import type { DataSourceQO } from '/@/model/cn/core/kpis/qo/DataSourceQO'
import type { DataSourceVO } from '/@/model/cn/core/kpis/vo/DataSourceVO'

interface DataSourceState {
}

export const useDataSourceStore = defineStore({
  id: 'dataSource',
  state: (): DataSourceState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.save(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.saveBatch(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.update(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.updateBatch(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.remove(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.removeBatch(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<DataSourceQO>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.count(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<DataSourceQO>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.pk(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<DataSourceQO>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.query(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<DataSourceQO>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.paging(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<DataSourceQO>): Promise<Res<DataSourceVO>> {
      return new Promise<Res<DataSourceVO>>((resolve, reject) => {
        dataSourceService.countVo(param).then((res: AxiosResponse<Res<DataSourceVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<DataSourceQO>): Promise<Res<DataSourceVO>> {
      return new Promise<Res<DataSourceVO>>((resolve, reject) => {
        dataSourceService.pkVo(param).then((res: AxiosResponse<Res<DataSourceVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<DataSourceQO>): Promise<Res<DataSourceVO>> {
      return new Promise<Res<DataSourceVO>>((resolve, reject) => {
        dataSourceService.queryVo(param).then((res: AxiosResponse<Res<DataSourceVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<DataSourceQO>): Promise<Res<DataSourceVO>> {
      return new Promise<Res<DataSourceVO>>((resolve, reject) => {
        dataSourceService.pagingVo(param).then((res: AxiosResponse<Res<DataSourceVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    dataImport(param: Param<string>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.dataImport(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    dataExport(param: Param<DataExportAO<DataSourceQO>>): Promise<Res<string>> {
      return new Promise<Res<string>>((resolve, reject) => {
        dataSourceService.dataExport(param).then((res: AxiosResponse<Res<string>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    addDataSource(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.addDataSource(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    uninstallDataSource(param: Param<DataSource>): Promise<Res<DataSource>> {
      return new Promise<Res<DataSource>>((resolve, reject) => {
        dataSourceService.uninstallDataSource(param).then((res: AxiosResponse<Res<DataSource>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useDataSourceStoreWithout() {
  return useDataSourceStore(store)
}
